@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem  Grails startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
:: 应用服务器端口
set APP_PORT=8080

:: 设置环境变量
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_151
set GRAILS_VERSION=3.1.6
set GRAILS_HOME=C:\grails-%GRAILS_VERSION%

set PATH=%GRAILS_HOME%\bin;%PATH%
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseConcMarkSweepGC -XX:ParallelGCThreads=2 -Dfile.encoding=UTF-8 -Dgroovy.source.encoding=UTF-8
:: set GRAILS_OPTS=-Xmx128m %GRAILS_OPTS%
::echo " %* " | find " run-app " > nul && set GRAILS_OPTS=-server -Dserver.port=%APP_PORT% -Xmx384m %GRAILS_OPTS%

:_grails_command
:: 若工程未编译，则在运行或进入交互模式前先编译，避免启动异常，奇怪现在工程好像没有target了
:: echo " %* " | find " run-app " > nul && if not exist "target\classes\BuildConfig.class" (grails compile && g %1 %2 %3 %4 %5 %6 %7 %8 %9 && goto exit)
:: echo " X%*X " | find " XX "    > nul && if not exist "target\classes\BuildConfig.class" (grails compile && g %1 %2 %3 %4 %5 %6 %7 %8 %9 && goto exit)

:: 当前路径=应用名称
::for /f "delims=" %%i in ("%cd%") do set APP_NAME=%%~ni

:: 运行 -- 没有参数则进入交互模式
grails %1 %2 %3 %4 %5 %6 %7 %8 %9

:exit
